package de.ifi.lmu.snitzelhunt.basics;

import java.util.ArrayList;
import java.util.Date;

/**
 * Class for the Route Object, the core object of Snitzelhunt
 * 
 * @author jaschkowitz
 * 
 */
public class Route {
	// server Database ID
	private long global_routeId;
	// local sqlite Database ID
	private long local_routeID;
	private String creator;
	private String name;
	private ArrayList<User> users;
	private ArrayList<Task> tasks;
	private Date startDate;
	private Date endDate;

	/**
	 * simple constructor for setting all fields
	 * 
	 * @param global_routeId
	 * @param local_routeID
	 * @param creator
	 * @param users
	 * @param name
	 * @param tasks
	 * @param startDate
	 * @param endDate
	 */
	public Route(long global_routeId, long local_routeID, String creator,
			ArrayList<User> users, String name, ArrayList<Task> tasks,
			Date startDate, Date endDate) {
		super();
		this.creator = creator;
		this.users = users;
		this.name = name;
		this.tasks = tasks;
		this.startDate = startDate;
		this.endDate = endDate;
		this.global_routeId = global_routeId;
		this.local_routeID = local_routeID;
	}

	/**
	 * no args constructor for gson
	 */
	public Route() {
	}

	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	public ArrayList<User> getUsers() {
		return users;
	}

	public void setUsers(ArrayList<User> users) {
		this.users = users;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public ArrayList<Task> getTasks() {
		return tasks;
	}

	public void setTasks(ArrayList<Task> tasks) {
		this.tasks = tasks;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public int nrOfParticipants() {
		return users.size();
	}

	public int nrOfTasks() {
		return tasks.size();
	}

	public long getGlobal_routeId() {
		return global_routeId;
	}

	public void setGlobal_routeId(long global_routeId) {
		this.global_routeId = global_routeId;
	}

	public long getLocal_routeID() {
		return local_routeID;
	}

	public void setLocal_routeID(long local_routeID) {
		this.local_routeID = local_routeID;
	}

	public void addTask(Task newTask) {
		tasks.add(newTask);
	}

	@Override
	public String toString() {
		StringBuilder sbuild = new StringBuilder();
		sbuild.append(getClass().getName() + " [global_routeId="
				+ global_routeId + " ,local_routeID=" + local_routeID
				+ " ,creator=" + creator + " ,name=" + name + " ,startDate="
				+ startDate.getTime() + " ,endDate=" + endDate.getTime()
				+ " ,startDate=" + startDate.toString() + " ,endDate="
				+ endDate.toString() + "]");
		sbuild.append("\n Tasks:");
		for (Task task : getTasks()) {
			sbuild.append("\n" + task.toString());
		}
		sbuild.append("\n Users:");
		for (User user : getUsers()) {
			sbuild.append("\n" + user.toString());
		}

		return sbuild.toString();
	}
}
